<? session_start();
						
include_once ('core/conn.php');
						
$db = get_conn();
						
check_session();
					
						
					
?>
<html>
<head>

<link href="tools/modal/base.css" type="text/css" rel="stylesheet" />
<link href="tools/modal/modal-window.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" lang="javascript" src="tools/modal/jquery-1.3.2.min.js"></script>
<script type="text/javascript" lang="javascript" src="tools/modal/modal-window.min.js"></script>
<script>
function refresh_list(){
	document.location.href=document.location.href;	

}

function check_all(){
	
}
</script>
</head>

<body>
<fieldset>
Pagos por recibir
<form name='invoices' method='post' action='/core/invoices.php' onsubmit='return checkdata(this)'>
  <table width="80%" border="0">

    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><? 
			
		$sql = "select 
				i.id_invoice, i.amount, i.due_date, i.exp_date, i.description, l.number, l.id_location, it.name, i.description , 
				p.pdate, p.description, p.id_payment, p.receive_file
				from 
				`invoices` i , `locations` l , `invoices_type` it , `payments` p
				where 
				i.istatus='C' and 
				i.id_location = l.id_location and 
				l.id_location = p.id_location and
				p.id_invoice = i.id_invoice and 
				i.id_it = it.id_it 
				order by i.id_invoice";
		//echo $sql;
		$result = mysql_query($sql);
		if($result){
			$data ="<table width='100%' border='1' align='left' >";

			if(mysql_num_rows($result) > 0){
					$data .="<tr>

						<td align='left' >
							ID
						</td>
						<td align='left' >
							Filial
						</td>							
						<td align='left' >
							Tipo
						</td>
						
						<td align='left' >
							Fecha Cobro
						</td>	
						
						
						<td align='left' >
							Fecha Pago
						</td>												
						
						<td align='left' >
							Monto
						</td>	
						<td align='left' >
							# REF
						</td>	
						<td align='left' >
							Recivo
						</td>							
						<td align='left' >
							&nbsp;
						</td>																														
						</tr>";			
				$data .="<tr>
					<td align='left' colspan='9'>
						<hr size='1'>
					</td>						
					</tr>";				
								
				while($row = mysql_fetch_array($result)){
					//$owner_name = get_owner_name($row['id_location']);
					if($row['receive_file']!=''){
						$link_recibo ="<a onClick='$(this).modal({width:350, height:350}).open(); return false;' href='file_storage/recibos/".$row['receive_file']."'>Ver</a>";

					}
					
					
					$data .="<tr>

						<td align='left' >
							".$row['id_invoice']."
						</td>						
						<td align='left' >
							".$row['number']." 
						</td>
						<td align='left' >
							".$row['name']."
						</td>													
						<td align='left' >
							".format_date($row['due_date'])."
						</td>
						
						<td align='left' >
							".($row['pdate'])."
						</td>						

						<td align='center' >
							".format($row['amount'],2)."
						</td>	
						<td align='left' >
							".$row['description']."
						</td>
						
						<td align='left' >
							".$link_recibo."
						</td>							
						
						<td align='left' >
							<a href='core/invoices.php?act=rp&id_invoice=".$row['id_invoice']."&id=".$row['id_payment']."'>Confirmar Pago</a>
						</td>																														
						</tr>";
						
						$total = $total + $row['amount'];
					
				}//while
				
					$data .="<tr>

						<td align='left' colspan='9'>
							<hr size='1'>
						</td>						
						</tr>";
										
					$data .="<tr>

						<td align='right' colspan='5'>
							Total
						</td>						
						<td align='center' >
							".format($total,2)."
						</td>	
						<td align='left' >
							&nbsp;
						</td>																								
						</tr>";
				
				
			}//if
				
			else{
					
				$data .= "<tr><td align='center'>No hay Pagos pendientes</td></tr>";			
				
			}
				
			$data .="</table>";
			
		}else{
				
			error_handling($sql,mysql_error());
			
		}
			
		echo $data;
			
		?>&nbsp;</td>
    </tr>
  </table>
</form>
</fieldset>

</body>
</html>
